<?php 
include("header.php");
require_once "../dao/user_dao.php";
require_once "../../config/tanggal.php";

echo "<div class='container'>
		<div class='row'>";

include("sidebar.php");
	
$modul = $_GET['modul'];

$user = new User_Dao($class_db);

echo "<div class=span7>";

$q = "SELECT user_id FROM user WHERE username='".$log->getUserName()."'";

//print_r($q);

$id = $class_db->select_table($q);
//$id=1;
//print_r($id);

foreach($id as $data){
    $id = $data['user_id'];
}
//print_r($id);

switch($modul){
    
    default:
        
        echo "<p>Silahkan memilih menu disamping kanan untuk mengubah data user/pelanggan serta melihat riwayat order anda</p>";
        
        
    break;
    
    case "user";
        $user_data = $user->get_user_information($id);
        
        if(!$user_data){
            $user_data = $user->get_user($id);
        }
        foreach($user_data as $data){
        echo "<form name=fr_user class=form method=POST onSubmit='return selesai()' action='my_account_aksi.php?modul=user'  enctype=multipart/form-data>
            <input type=hidden name=id value=$data->user_id>
            <table class=table>
            <tr><td colspan=2>INFORMASI USER</td></tr>
            <tr><td>Nama User</td><td><input type=text name=username value=$data->username></td></tr>
            <tr><td>Password</td><td><input type=text name=password value=$data->password></td></tr>
            <tr><td>Pertanyaan Reset Password</td><td><input type=text name=reset_quest value=$data->reset_quest></td></tr>
            <tr><td>Jawaban Reset Password</td><td><input type=text name=reset_answer value=$data->reset_answer></td></tr>
            <tr><td colspan=2><input class='btn btn-primary' type=submit value=simpan></td></tr>
            </table></form>";    
        }
    break;
    
    case "biodata";
        $user_data = $user->get_user_information($id);
        if($user_data){
                foreach($user_data as $data){
                $cid = $data->customer_id;
                //print_r($cid);
                if(count($data>0)){
                    echo "<form class=form method=POST action='my_account_aksi.php?modul=biodata' onSubmit='return selesai()' enctype=multipart/form-data>
                    <input type=hidden name=id value=$cid>";
                }else{
                    echo "<form class=form method=POST action='my_account_aksi.php?modul=addbiodata' onSubmit='return selesai()' enctype=multipart/form-data>
                    <input type=hidden name=id value=$data->user_id>";
                }
            
                echo "<table class=table>
                <tr><td colspan=2>BIODATA PELANGGAN</td></tr>
                <tr><td>Nama </td><td><input type=text name=name value=$data->name></td></tr>
                <tr><td colspan=2>Alamat </td></tr>
                <tr><td>Jalan</td><td><textarea name=street>$data->street</textarea></td></tr>
                <tr><td>Kecamatan</td><td><input type=text name=kecamatan value=$data->kecamatan></td></tr>
                <tr><td>Kabupaten/Kota</td><td><select name=city>";
                $class_db->hasil="";
                $class_db->show_Data('t_city','*',null,null,'province_id='.$data->province);
                $city = $class_db->hasil;
                foreach($city as $hasil){
                    if($hasil['city_id']==$data->city){
                        echo "<option value=$hasil[city_id] selected>$hasil[city_name]</option>";
                    }else{
                        echo "<option value=$hasil[city_id]>$hasil[city_name]</option>";
                    }
                }
                
                echo "</select></td></tr>
                <tr><td>Provinsi</td><td><select name=province>";
                $class_db->hasil="";
                $class_db->show_Data('t_province');
                $province = $class_db->hasil;
                foreach($province as $hasil){
                    if($hasil['province_id']==$data->province){
                        echo "<option value=$hasil[province_id] selected>$hasil[name]</option>";
                    }else{
                        echo "<option value=$hasil[province_id]>$hasil[name]</option>";
                    }
                }
                
                echo "</select></td></tr>
                <tr><td>Kode Pos</td><td><input type=text name=zip_code value=$data->zip_code></td></tr>
                <tr><td>Telepon</td><td><input type=text name=telephone value=$data->telephone></td></tr>
                <tr><td></td><td><div class=span2><img src='../../images/customer/$data->photo'></div></td></tr>
                <tr><td>Foto</td><td><input type=file name=photo></td></tr>
                <tr><td colspan=2><input class='btn btn-primary' type=submit value=simpan></td></tr>
                </table></form>";    
            }
        }else{
            
                echo "<form class=form method=POST action='my_account_aksi.php?modul=addbiodata' onSubmit='return selesai()' enctype=multipart/form-data>
                    <input type=hidden name=id value=$id>";
                           
                echo "<table class=table>
                <tr><td colspan=2>BIODATA PELANGGAN--</td></tr>
                <tr><td>Nama </td><td><input type=text name=name ></td></tr>
                <tr><td colspan=2>Alamat </td></tr>
                <tr><td>Jalan</td><td><textarea name=street></textarea></td></tr>
                <tr><td>Kecamatan</td><td><input type=text name=kecamatan ></td></tr>
                <tr><td>Kabupaten/Kota</td><td><select name=city>";
                $class_db->hasil="";
                $class_db->show_Data('t_city');
                $city = $class_db->hasil;
                foreach($city as $hasil){                    
                        echo "<option value=$hasil[city_id]>$hasil[city_name]</option>";
                    
                }
                
                echo "</select></td></tr>
                <tr><td>Provinsi</td><td><select name=province>";
                $class_db->hasil="";
                $class_db->show_Data('t_province');
                $province = $class_db->hasil;
                foreach($province as $hasil){                    
                        echo "<option value=$hasil[province_id]>$hasil[name]</option>";
                   
                }
                
                echo "</select></td></tr>
                <tr><td>Kode Pos</td><td><input type=text name=zip_code ></td></tr>
                <tr><td>Telepon</td><td><input type=text name=telephone ></td></tr>
                <tr><td></td><td><img src='../../images/customer/$data->photo'></td></tr>
                <tr><td>Foto</td><td><input type=file name=photo></td></tr>
                <tr><td colspan=2><input class='btn btn-primary' type=submit value=simpan></td></tr>
                </table></form>"; 
        }
        
    break;
    
    case "order":
        include "../../config/paging.php";
        $p = new Paging;
        $batas = 10;
        $posisi = $p->cari_posisi($batas);
        
        $q = "SELECT customer_id FROM customer WHERE user_id=".$id;
        //print_r($q);
        $id_customer = $class_db->select_table($q);
        
        foreach($id_customer as $hasil){
            $id_customer = $hasil['customer_id'];
        }
        $order = $user->get_order($id_customer, $posisi, $batas);
        $tgl = new Tanggal();
        
        echo "<table class=table>
            <tr><td colspan=2>RIWAYAT ORDER ANDA</td></tr>
            <tr><th>No</th><th>Nomor PO</th><th>Tanggal Order</th><th>Nilai</th><th>Status</th></tr>";
        $no=$posisi+1;    
        foreach($order as $data){
        $tgl->set_tgl($data->order_date);
        $tanggal = $tgl->get_tgl_indo();   
        $nilai = number_format($data->nilai,2,',','.'); 
        echo "     
            <tr><td>$no</td><td>$data->nomor_po</td><td>$tanggal</td><td halign=right>$nilai</td><td>$data->status</td></tr>
            
            ";
            $no++;    
        }
        
        echo "<tr><td colspan=5></td></tr></table>";
        
        $order2 = $user->get_order($id_customer);
        
        $jml_data = count($order2);
        //print_r($jml_data);
        
        $jml_halaman = $p->jml_halaman($jml_data,$batas);
        //print_r($jml_halaman);
        
        $link_halaman = $p->navHalaman($modul,$_GET['halaman'],$jml_halaman);
        
        echo $link_halaman."";
    break;
} 

echo "</div><div class=span2>

    <table class=table>
    <tr><td><a href='my_account.php?modul=user'>data user</a></td></tr>
    <tr><td><a href='my_account.php?modul=biodata'>data pelanggan</a></td></tr>
    <tr><td><a href='my_account.php?modul=order'>riwayat order</a></td></tr>
    <tr><td></td></tr>
    </table>";

echo "</div></div>";



include("footer.php");
?>
<script src="js/jquery.js"></script>
        <script src="js/bootstrap.js"></script>
<script language = "javascript">


function selesai()
{
    
  var answer = confirm ("Anda yakin menyimpan perubahan?")
    if (answer)
        return true;
    else
        
        return false;
    }
</script>
	